package com.example.pinkcat;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;

import com.example.pinkcat.adapter.Tuijianye_FragmentPagerAdapter;
import com.google.android.material.tabs.TabLayout;

public class Activity_tuijian_ye extends AppCompatActivity {

    private TabLayout mTablayout;
    private ViewPager mViewPager;
    private Tuijianye_FragmentPagerAdapter tuijianye_fragmentPagerAdapter;

    private TabLayout.Tab one;
    private TabLayout.Tab two;
    private TabLayout.Tab three;
    private TabLayout.Tab four;
    private TabLayout.Tab five;
    private TabLayout.Tab six;
    private TabLayout.Tab seven;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //getSupportActionBar().hide();//隐藏掉整个ActionBar
        setContentView(R.layout.activity_main);

        //初始化视图
        initViews();
    }

    private void initViews() {
        //使用适配器将ViewPager与Fragment绑定在一起
        mViewPager = (ViewPager) findViewById(R.id.viewPage);
        tuijianye_fragmentPagerAdapter = new Tuijianye_FragmentPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(tuijianye_fragmentPagerAdapter);

        //将TabLayout与ViewPager绑定在一起
        mTablayout = (TabLayout) findViewById(R.id.tablayout);
        mTablayout.setupWithViewPager(mViewPager);

        //指定Tab的位置
        one =  mTablayout.getTabAt(0); //推荐页
        two =  mTablayout.getTabAt(1); //热门
        three = mTablayout.getTabAt(2); //动漫
        four = mTablayout.getTabAt(3); //电影
        five = mTablayout.getTabAt(4); //电视剧
        five = mTablayout.getTabAt(5); //综艺
        six = mTablayout.getTabAt(6);  //游戏
        seven = mTablayout.getTabAt(7);


    }
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
}